from vector import vector
import rendering, enemy, mapa
class player:
    def __init__(self,surface,x,y):
        self.body = rendering.r_object(surface,(0,0,255,100),10,10)
        self.pos = vector(x,y)
        self.dir = vector(x,y-10)
        self.hp = 100
    def collides(self,string):
        for i in mapa.col:
            if i == string:
                return True
                break
    def moveUp(self):
        if self.collides(str((self.pos.get()[0])/10)+"x"+str((self.pos.get()[1]-10)/10))!= True:
            self.pos.sub(vector(0,10))
            self.draw(self.pos)
            self.dir.change(self.pos)
            self.dir.sub(vector(0,10))
            print "Pozice hrace je:" + str(self.pos.get())
            print "Pozice dir je:" + str(self.dir.get())
    def moveDown(self):
        if self.collides(str((self.pos.get()[0])/10)+"x"+str((self.pos.get()[1]+10)/10))!= True:
            self.pos.add(vector(0,10))
            self.draw(self.pos)
            self.dir.change(self.pos)
            self.dir.add(vector(0,10))
            print "Pozive hrace je:" + str(self.pos.get())
            print "Pozice dir je:" + str(self.dir.get())
    def moveRight(self):
        if self.collides(str((self.pos.get()[0]+10)/10)+"x"+str((self.pos.get()[1])/10))!= True:
            self.pos.sub(vector(10,0))
            self.draw(self.pos)
            self.dir.change(self.pos)
            self.dir.sub(vector(10,0))
            print "Pozice hrace je:" + str(self.pos.get())
            print "Pozice dir je:" + str(self.dir.get())
    def moveLeft(self):
        print mapa.col
        if self.collides(str((self.pos.get()[0]-10)/10)+"x"+str((self.pos.get()[1])/10))!= True:
            self.pos.add(vector(10,0))
            self.draw(self.pos)
            self.dir.change(self.pos)
            self.dir.add(vector(10,0))
            print "Pozice hrace je:" +str(self.pos.get())
            print "Pozice dir je:" + str(self.dir.get())
    def draw(self,vec):
        self.body.draw(vec)
    def think(self):
        self.body.draw(self.pos)
    def getPos(self):
        return self.pos.get()
    def hurt(self,val):
        self.hp = self.hp - val
    def heal(self,val):
        self.hp = self.hp + val
    def returnDir(self):
        return self.dir.get()
    def attack(self):
        for i in enemy.enemyField:
            if i.get() == self.dir.get():
                i.die()
    def returnRect(self):
        return self.body.getRect()
